#include <ProcessThread/ProcessThread.h>

static inline BOOL IsTCBIdle(LPThreadControlBlock lpTCB);
/*
@brief 将 TCB 添加到 TCB 队列尾部
@param lpTCBQueue TCB 队列
@param lpTCB 待添加的 TCB
@return void
*/
void AppendTCBToQueue(LPTCBQUEUE lpTCBQueue, LPThreadControlBlock lpTCB)
{
    KERNEL_ASSERT(lpTCBQueue, "lpTCBQueue is NULL\r\n.");
    KERNEL_ASSERT(lpTCB , "lpTCB is NULL\r\n");
    if (IsTCBIdle(lpTCB)) return; /* 对傀儡 TCB 不作处理 */
    LPThreadControlBlock lpPrev = lpTCBQueue->lpPrev;
    lpTCB->lpPrev = lpPrev;
    lpTCB->lpNext = lpTCBQueue;
    lpPrev->lpNext = lpTCB;
    lpTCBQueue->lpPrev = lpTCB;
}

/*
@brief 判断 TCB 是否为傀儡 TCB
@note 就绪队列中若无可调度线程，则傀儡线程会被调度上处理器运行，傀儡线程常驻就绪队列，指派傀儡线程不会导致傀儡线程就绪移出队列
*/
static inline BOOL IsTCBIdle(LPThreadControlBlock lpTCB)
{
    return lpTCB->bIsIdle;
}